import {_decorator, Button, Component, instantiate, Label, Prefab, Node, Sprite, resources, SpriteFrame} from 'cc';
import {configsHelper} from "db://assets/script/configs-helper";
import {lobby} from "db://assets/script/lobby";
import {PropDesc} from "db://assets/script/game/mainui/props/prop-desc";
import Long from "long";

const {ccclass, property} = _decorator;

@ccclass('Peculiarity')
export class Peculiarity extends Component {

    @property(Button)
    peculiarityText!: Button

    @property(Prefab)
    tipsPrefab!: Prefab;

    start() {

    }

    setPeculiarity(peculiarityId: Long) {
        const pc = configsHelper.loadPeculiarityConfig(peculiarityId)!
        this.peculiarityText.node.getChildByName("Label")!.getComponent(Label)!.string = pc.name
        const iconPath = configsHelper.loadPeculiarityBg(pc.quality)
        if (iconPath) this.peculiarityText.getComponent(Sprite)!.spriteFrame = resources.get(iconPath, SpriteFrame)!
        this.peculiarityText.node.on(Button.EventType.CLICK, () => this.showSkillTips(this.peculiarityText.node, peculiarityId))
    }

    showSkillTips(targetNode: Node, peculiarityId: Long) {
        const tn = instantiate(this.tipsPrefab)
        lobby.instance.gui.addChild(tn)
        const propDesc = tn.getComponent(PropDesc)!
        propDesc.initPeculiarity(targetNode, peculiarityId)
    }


    update(deltaTime: number) {

    }
}

